/**
 *
 * cookie内容
 * @type {string}
 */
/**
 * 购物车
 * @memberOf {TypeName} 
 * @return {TypeName} 
 */
var cookie_car_final = "cookie_car";
/**
 * 商户ID
 * @memberOf {TypeName} 
 * @return {TypeName} 
 */
var cookie_sid_final = "sid";
/**
 * 商品分类  一级分类ID
 * @memberOf {TypeName} 
 * @return {TypeName} 
 */
var cookie_classifyId_final = "classifyId";

/**
 * 商品分类  二级分类ID
 * @memberOf {TypeName} 
 * @return {TypeName} 
 */
/**
 * 选中的二级分类
 * @memberOf {TypeName} 
 * @return {TypeName} 
 */
var cookie_choiceClassifyId_final = "choiceClassifyId";

/**
 * 用户ID
 * @memberOf {userId} 
 */
var cookie_uid_final = "userId";
/**
 * 用户名
 * @memberOf {userName} 
 */
var cookie_uname_final = "userName";
/**
 * 用户手机号
 * @memberOf {mobile} 
 */
var cookie_mobile_final = "mobile";
/**
 * 登录验证码
 */
var cookie_loginCheckCode_final = "loginCheckCode";
/**
 * 登录验证码
 */
var cookie_registerCheckCode_final = "registerCheckCode";

/**
 * 商品对象
 */
function Product() {
    var id = "";
    var price=0;
	var startSaleNum=0; //起购量
	var purchaseNum=0;   //限购量
	var cartId="";	 //购物车里对应该商品编号
	var number=0;   //购物车里对应该商品购买数量
	var amount=0;	//购物车里对应该商品购买金额
	
	//add clu
	var updateDate="";
	
	//新增属性
	var name="";//商品名称
	var assisTitle="";//商品全称
	var logoUrl="";
	var originalPrice=0;

	this.setName=function(name){
		this.name = name;
	}
	this.getName=function(){
		return this.name;
	}
	this.setAssisTitle=function(assisTitle){
		this.assisTitle = assisTitle;
	}
	this.getAssisTitle=function(){
		return this.assisTitle;
	}
	this.setLogoUrl=function(logoUrl){
		this.logoUrl = logoUrl;
	}
	this.getLogoUrl=function(){
		return this.logoUrl;
	}
	this.setOriginalPrice=function(originalPrice){
		this.originalPrice = originalPrice;
	}
	this.getOriginalPrice=function(){
		return this.originalPrice;
	}
	
	this.setId=function(id){
		this.id = id;
	}
	this.getId=function(){
		return this.id;
	}
	this.setPrice=function(price){
		this.price = price;
	}
	this.getPrice=function(){
		return this.price;
	}
	this.setStartSaleNum=function(startSaleNum){
		this.startSaleNum = startSaleNum;
	}
	this.getStartSaleNum=function(){
		return this.startSaleNum;
	}
	this.setPurchaseNum=function(purchaseNum){
		this.purchaseNum = purchaseNum;
	}
	this.getPurchaseNum=function(){
		return this.purchaseNum;
	}
	this.setNumber=function(number){
		this.number = number;
	}
	this.getNumber=function(){
		return this.number;
	}
	this.setAmount=function(amount){
		this.amount = amount;
	}
	this.getAmount=function(){
		return this.amount;
	}
	this.setUpdateDate=function(updateDate){
		this.updateDate = updateDate;
	}
	this.getUpdateDate=function(){
		return this.updateDate;
	}
	

    this.toJson_ = function(){
        var p1 ="{id:'"+this.id+
        "',price:'"+this.price+
        "',startSaleNum:'"+this.startSaleNum+
        "',purchaseNum:'"+this.purchaseNum+
        "',number:'"+this.number+
        "',amount:'"+this.amount+
        "',name:'"+this.name+
        "',assisTitle:'"+this.assisTitle+
        "',logoUrl:'"+this.logoUrl+
        "',originalPrice:'"+this.originalPrice+
        "',updateDate:'"+this.updateDate+
        "'}" ;
        return p1;
    }
};

/**
 * 操作cookie 内容对象
 */
function MallCookieService (){
    /**
     * cookie 默认参数配置
     * @type {{path: string, expires: number}}
     */
    var request_cookie = {
        path:"/",
        expires:(30* 24 * 60 * 60 * 1000)
    };
    
    var request_loginCheckCode_cookie = {
        path:"/",
        expires:(30 * 60 * 1000)
    };
    
    var request_registerCheckCode_cookie = {
            path:"/",
            expires:(30 * 60 * 1000)
        };
    
    function isArray(value){
    	var saveValues = "";
    	if(value instanceof Array){
    		var le = value.length-1;
    		$.each(value,function(i,p1){
            	saveValues += p1  ;
            	if(i != le){
            		saveValues += "、";
            	}
        	});
    	}else{
    		saveValues = value;
    	}
    	return saveValues;
    }

    /**
     * 添加cookie内容
     * @param key
     * @param value
     */
    function add(key,value){
    	value = isArray(value);
        $.cookie(key,value,request_cookie);
    };
    
    function addLoginCheckCode(key,value){
    	value = isArray(value);
        $.cookie(key,value,request_loginCheckCode_cookie);
    }
    
    function addRegisterCheckCode(key,value){
    	value = isArray(value);
        $.cookie(key,value,request_registerCheckCode_cookie);
    }

    /**
     * 获取cookie内容
     * @param key
     * @returns {*}
     */
    function cookie_get(key){
    	var value = $.cookie(key);
    	if(value != null){
    		if(value.indexOf("、") >= 0){
    			value = value.replace(/、/g, ",");
    		}
    	}
    	
        return value;
    };

    /**
     * <商品>json  转换对象
     */
    function product_copy_json_to_Object(jsonObject){
        var product = new Product();
        product.setId(jsonObject.id);
        product.setPrice(jsonObject.price);
        product.setStartSaleNum(jsonObject.startSaleNum);
        product.setPurchaseNum(jsonObject.purchaseNum);
        product.setNumber(jsonObject.number);
        product.setAmount(jsonObject.amount);
        product.setName(jsonObject.name);
        product.setAssisTitle(jsonObject.assisTitle);
        product.setLogoUrl(jsonObject.logoUrl);
        product.setOriginalPrice(jsonObject.originalPrice);
        product.setUpdateDate(jsonObject.updateDate);
        return product;

    }

    /**
     * <商品>对象复制对象
     * @private
     */
    function product_copy_Object_to_Object(editProduct){
        var product = new Product();
        product.setId(editProduct.getId());
        product.setPrice(editProduct.getPrice());
        product.setStartSaleNum(editProduct.getStartSaleNum());
        product.setPurchaseNum(editProduct.getPurchaseNum());
        product.setNumber(editProduct.getNumber());
        product.setAmount(editProduct.getAmount());
        product.setName(editProduct.getName);
        product.setAssisTitle(editProduct.getAssisTitle);
        product.setLogoUrl(editProduct.getLogoUrl);
        product.setOriginalPrice(editProduct.getOriginalPrice);
        product.setUpdateDate(editProduct.updateDate);
        return product;
    }

    /**
     * 获取所有购物车内容<对象类型>
     *    【object,object】
     */
    this.getCarsObject = function(){
        var resultCars = [];
        var cars = eval("[" + cookie_get(cookie_car_final) + "]");
        $.each(cars,function(i,p1){
            if(p1 != null && p1 != undefined){
                resultCars.push(product_copy_json_to_Object(p1));
            }
        });
        return resultCars;
    };
    /**
     * 获取所有购物车内容<Json字符类型类型>
     *     【{json}，{json}】;
     */
    this.getCarsJson = function(){
        var resultCars = [];
        var cars = eval("[" + cookie_get(cookie_car_final) + "]");
        $.each(cars,function(i,p1){
            if(p1 != null && p1 != undefined){
                resultCars.push(product_copy_json_to_Object(p1).toJson_());
            }
        });
        return resultCars;
    };

    /**
     * 具有覆盖性质的操作<添加购物车>
     *      添加全部购物车
     *      ["{id:'"+this.id+"',num:'"+this.id+"',name:'"+this.name+"'}",{} ]
     * @param cars
     */
    this.addCars = function(cars){
        add(cookie_car_final,cars);
    };

    /**
     * 添加商品
     *      增加购物商品
     * @param product 一个商品
     * eg:
     *  Object
     */
    this.addProduct = function(newProduct){
        var cars = this.getCarsJson();
        if(cars == null || cars == undefined || cars.length == 0){
            cars = [];
        }
        cars.push(newProduct.toJson_());
        add(cookie_car_final,cars);
    };

    /**
     * 更新商品内容
     * @param editProduct
     */
    this.editProduct = function(editProduct){
        var newCar = [];
        var cars = this.getCarsObject();
        if(cars == null || cars == undefined || cars.length == 0){
            cars = [];
        }
        $.each(cars,function(i,p1){
            if(p1 != null && p1 != undefined){

                /**默认添加*/
                var product = product_copy_json_to_Object(p1);

                /**相同更新*/
                if(editProduct.getId() == p1.id){
                    product =product_copy_Object_to_Object(editProduct);
                }
                newCar.push(product.toJson_());
            }
        });
        add(cookie_car_final,newCar);
    };

    /**
     * 删除购物车商品，指定商品ID 删除
     * @param newProduct
     */
    this.delProduct = function(newProduct){
        var newCar = [];
        var cars = this.getCarsObject();
        if(cars == null || cars == undefined || cars.length == 0){
            cars = [];
        }
        $.each(cars,function(i,p1){
            if(p1 != null && p1 != undefined){
                if(newProduct.getId() != p1.id){
                    newCar.push(product_copy_json_to_Object(p1).toJson_());
                }

            }
        });
        add(cookie_car_final,newCar);
    };

    /**
     * 根据ID查询商品
     * @param strId  返回对象
     *  Object
     */
    this.findByIdProduct = function(strId){
        var findProject = null;
        var cars = this.getCarsObject();
        if(cars == null || cars == undefined || cars.length == 0){
            cars = [];
        }
        $.each(cars,function(i,p1){
            if(p1 != null && p1 != undefined){
                if(strId == p1.id){
                    findProject = product_copy_json_to_Object(p1);
                }
            }
        });
        return findProject;
    };
    
    /**
     * 设置商户SID
     */
    this.setSID = function(sid){
    	add(cookie_sid_final,sid);
    }
    /**
     * 获取商户SID
     * @param {Object} sid
     */
    this.getSID = function(sid){
    	return cookie_get(cookie_sid_final);
    }
    this.setClassifyId = function(classifyId){
    	add(cookie_classifyId_final,classifyId);
    }
 	this.getClassifyId = function(){
    	return cookie_get(cookie_classifyId_final);
    }
    this.setChoiceClassifyId = function(classifyId){
    	add(cookie_choiceClassifyId_final,classifyId);
    }
 	this.getChoiceClassifyId = function(){
    	return cookie_get(cookie_choiceClassifyId_final);
    }
 	
    this.setUserId = function(userId){
    	add(cookie_uid_final,userId);
    }
    this.getUserId = function(userId){
    	return cookie_get(cookie_uid_final);
    }
    this.setUserName = function(userName){
    	add(cookie_uname_final,userName);
    }
    this.getUserName = function(userName){
    	return cookie_get(cookie_uname_final);
    }
    this.setMobile = function(mobile){
    	add(cookie_mobile_final,mobile);
    }
    this.getMobile = function(mobile){
    	return cookie_get(cookie_mobile_final);
    }
    this.setLoginCheckCode = function(checkCode){
    	addLoginCheckCode(cookie_loginCheckCode_final,checkCode);
    }
    this.getLoginCheckCode = function(){
    	return cookie_get(cookie_loginCheckCode_final);
    }
    this.setRegisterCheckCode = function(checkCode){
    	addRegisterCheckCode(cookie_registerCheckCode_final,checkCode);
    }
    this.getRegisterCheckCode = function(){
    	return cookie_get(cookie_registerCheckCode_final);
    }
}

/**显示总金额 + 购物车数量+商品数量*/
function showProductCar(productCarPriceSum,productCarOrderNum,productCurrentNum,productId){
	productCarPriceSum = productCarPriceSum.toFixed(2);
	$("#sl").text(productCarPriceSum);
	$("#car_num").text(productCarOrderNum);
	if(productCurrentNum != null){
		$("#sl_product" +productId ).text(productCurrentNum);
	}
	
}
/**
 * 减少购买商品
 */

function mall_diffProductCart(productId)
{
	var cookieService = new  MallCookieService();
	var productCarPriceSum = 0;//总价格
	var productCarOrderNum = 0;//订单总数
	var productCurrentNum = 0;//当前商品显示数量
	
	/**获取当前商品对象*/
	var product = new Product();
	for(var i in products){
		if(productId==products[i].id){
			product = products[i];
		}
	}
	
	/**验证cookie是否存在*/
	var cookieProduct = cookieService.findByIdProduct(productId);
	if(cookieProduct == null ){
		//alert("抱歉，当前商品限起购数量 "+product.startSaleNum+" 件，不能再低了。");
	}else{
		if(cookieProduct.getNumber() <= 0){
			alert("抱歉，当前商品限起购数量 "+product.startSaleNum+" 件，不能再低了。");
			return;
		}else{
			if(cookieProduct.getNumber()-1>=product.startSaleNum){
				productCurrentNum = cookieProduct.getNumber() - 1;
			}else{
				//减去起购数量
				productCurrentNum = cookieProduct.getNumber() - product.startSaleNum;
			}
			cookieService.delProduct(cookieProduct);
			if(productCurrentNum > 0 ){
				cookieProduct.setNumber(productCurrentNum);
				cookieProduct.setUpdateDate(getNowDate());
				cookieService.addProduct(cookieProduct);
			}else{
				productCurrentNum = 0;
			}
		}
	}
	if(productCurrentNum <= 0){
		$("#imgdiff"+product.id).attr("src",ctxStatic+"/modules/bootstrap/img/diff-1.png");
	}else{
		$("#imgadd"+product.id).attr("src",ctxStatic+"/modules/bootstrap/img/add-2.png");
	}
	
	/*alert(product.number);
	if((product.number-1)<product.startSaleNum){ 如果在-1的情况下小雨		product.number = product.number-product.startSaleNum;		diffNum = product.startSaleNum;		$("#"+productId).find(".diff").attr("src", ctxFront+"/images/shop/diff-1.png");
	}else{
		product.number = product.number-1;
		diffNum = 1;
	}
	$("#"+productId).find(".add").attr("status", "1").attr("src", ctxFront+"/images/shop/add-2.png");*/
	
	
	/**获取购物车商品*/
	var cars = cookieService.getCarsObject();
	
	if(cars != null && cars.length > 0){
		$.each(cars,function(i,cookieCarProduct){
			productCarPriceSum += (cookieCarProduct.price * cookieCarProduct.getNumber());
			productCarOrderNum += numberConvertor(cookieCarProduct.getNumber());
		});
	}
	
	showProductCar(productCarPriceSum,productCarOrderNum,productCurrentNum,productId);
	
}

/**
 * 添加购买商品数量
 * @param {Object} productId
 * @return {TypeName} 
 */
function mall_addProductCart(productId){
	var cookieService = new  MallCookieService();
	var productCarPriceSum = 0;//总价格
	var productCarOrderNum = 0;//订单总数
	var productCurrentNum = 0;//当前商品显示数量
	
	/**获取当前商品对象*/
	var product = new Product();
	for(var i in products){
		if(productId==products[i].id){
			product = products[i];
		}
	}
	
	/**验证cookie是否存在*/
	var cookieProduct = cookieService.findByIdProduct(productId);
	
	/**新购商品*/
	if(cookieProduct == null ){
		cookieProduct = product;
		productCurrentNum = product.getStartSaleNum();
		cookieProduct.setNumber(productCurrentNum);
		cookieProduct.setUpdateDate(getNowDate());
		cookieService.addProduct(cookieProduct);
		$("#imgdiff"+product.id).attr("src",ctxStatic+"/modules/bootstrap/img/diff-2.png");
	/**已经存在购物车*/
	}else{
		var exceedNumber = 0;
		if(cookieProduct.getNumber()==0){
			exceedNumber = numberConvertor(cookieProduct.getNumber()) + parseFloat(product.getStartSaleNum());
		}else{
			exceedNumber = numberConvertor(cookieProduct.getNumber()) + 1;
		}
		
		/**是否设置限购*/
		if(product.getPurchaseNum() > 0 && exceedNumber > product.getPurchaseNum()){
			productCurrentNum = cookieProduct.getNumber();
			alert("抱歉，当前商品限购数量 "+product.getPurchaseNum()+" 件，不能再高了。");
			return;
		}else{
			productCurrentNum = exceedNumber;
		}
		
		if(null!=product.getPurchaseNum() && product.getPurchaseNum()>0){
			if(exceedNumber >= product.getPurchaseNum()){
				$("#imgadd"+product.id).attr("src",ctxStatic+"/modules/bootstrap/img/add-1.png");
			}else{
				$("#imgdiff"+product.id).attr("src",ctxStatic+"/modules/bootstrap/img/diff-2.png");
			}
		}
		
		/**保存数量*/
		cookieService.delProduct(cookieProduct);
		cookieProduct.setNumber(productCurrentNum);
		cookieProduct.setUpdateDate(getNowDate());
		cookieService.addProduct(cookieProduct);
		
	}
	
	/**获取购物车商品*/
	var cars = cookieService.getCarsObject();
	
	if(cars != null && cars.length > 0){
		$.each(cars,function(i,cookieCarProduct){
			productCarPriceSum += (numberConvertor(cookieCarProduct.price) * numberConvertor(cookieCarProduct.getNumber()));
			productCarOrderNum += numberConvertor(cookieCarProduct.getNumber());
		});
	}
	
	showProductCar(productCarPriceSum,productCarOrderNum,productCurrentNum,productId);
}

/**
 * 数据类型转换
 * @param {Object} number
 * @return {TypeName} 
 */
function numberConvertor(number){
	if(number == null || number == '' || number == undefined) return 0;
	return parseFloat(number);
}

/**
 * 初始化购物车商品列表
 */
function initProductCar(){
	var productCarPriceSum = 0;
	var productCarOrderNum = 0;
	
	var cookieService = new  MallCookieService();
	var cars = cookieService.getCarsObject();
	
	if(cars != null && cars.length > 0){
		$.each(cars,function(i,cookieCarProduct){
			productCarPriceSum += (numberConvertor(cookieCarProduct.price) * numberConvertor(cookieCarProduct.getNumber()));
			productCarOrderNum += numberConvertor(cookieCarProduct.getNumber());
			
			var number=cookieCarProduct.getNumber();
			var productId=cookieCarProduct.getId();
			var purchaseNum=cookieCarProduct.getPurchaseNum()
			$("#sl_product" +productId).text(number);
			
			if(number>0){
				$("#imgdiff"+productId).attr("src",ctxStatic+"/modules/bootstrap/img/diff-2.png");
			}

			if(null!=purchaseNum && purchaseNum>0){
				if(number>=purchaseNum){
					$("#imgadd"+productId).attr("src",ctxStatic+"/modules/bootstrap/img/add-1.png");
				}
			}
			
		});
	}
	showProductCar(productCarPriceSum,productCarOrderNum,null,null);
	
}

		

//收货人信息
/**
 * 收货人信息
 */
var cookie_member_final = "cookie_member";
/**
 * 商品对象
 */
function Member() {
    var name = "";
	var phone = "";
	var postcode = "";//是否默认，1为默认，0为非默认
	var country = "";
	var address = "";
	
	var id = "";
	var province = "";
	var city = "";
	this.setName=function(name){
		this.name = name;
	}
	this.getName=function(){
		return this.name;
	}
	this.setPhone=function(phone){
		this.phone = phone;
	}
	this.getPhone=function(){
		return this.phone;
	}
	this.setPostcode=function(postcode){
		this.postcode = postcode;
	}
	this.getPostcode=function(){
		return this.postcode;
	}
	this.setCountry=function(country){
		this.country = country;
	}
	this.getCountry=function(){
		return this.country;
	}
	this.setAddress=function(address){
		this.address = address;
	}
	this.getAddress=function(){
		return this.address;
	}
	this.setId=function(id){
		this.id = id;
	}
	this.getId=function(){
		return this.id;
	}
	this.setProvince=function(province){
		this.province = province;
	}
	this.getProvince=function(){
		return this.province;
	}
	this.setCity=function(city){
		this.city = city;
	}
	this.getCity=function(){
		return this.city;
	}
	

    this.toJson_ = function(){
        var m1 ="{name:'"+this.name+
        "',phone:'"+this.phone+
        "',postcode:'"+this.postcode+
        "',country:'"+this.country+
        "',address:'"+this.address+
        "',id:'"+this.id+
        "',province:'"+this.province+
        "',city:'"+this.city+
        "'}" ;
        return m1;
    }
};

/**
 * 操作cookie 内容对象
 */
function MemberCookieService (){
    /**
     * cookie 默认参数配置
     * @type {{path: string, expires: number}}
     */
    var request_cookie = {
        path:"/",
        expires:(30* 24 * 60 * 60 * 1000)
    };
    
    function isArray(value){
    	var saveValues = "";
    	if(value instanceof Array){
    		var le = value.length-1;
    		$.each(value,function(i,m1){
            	saveValues += m1  ;
            	if(i != le){
            		saveValues += "、";
            	}
        	});
    	}else{
    		saveValues = value;
    	}
    	return saveValues;
    }

    /**
     * 添加cookie内容
     * @param key
     * @param value
     */
    function add(key,value){
    	value = isArray(value);
        $.cookie(key,value,request_cookie);
    };

    /**
     * 获取cookie内容
     * @param key
     * @returns {*}
     */
    function cookie_get(key){
    	var value = $.cookie(key);
    	if(value != null){
    		if(value.indexOf("、") >= 0){
    			value = value.replace(/、/g, ",");
    		}
    	}
    	
        return value;
    };

    /**
     * <商品>json  转换对象
     */
    function member_copy_json_to_Object(jsonObject){
        var member = new Member();
        member.setName(jsonObject.name);
        member.setPhone(jsonObject.phone);
        member.setPostcode(jsonObject.postcode);
        member.setCountry(jsonObject.country);
        member.setAddress(jsonObject.address);
        member.setId(jsonObject.id);
        member.setProvince(jsonObject.province);
        member.setCity(jsonObject.city);
        return member;

    }

    /**
     * <商品>对象复制对象
     * @private
     */
    function member_copy_Object_to_Object(editMember){
        var member = new Member();
        member.setName(editMember.getName());
        member.setPhone(editMember.getPhone());
        member.setPostcode(editMember.getPostcode());
        member.setCountry(editMember.getCountry());
        member.setAddress(editMember.getAddress());
        member.setId(editMember.getId());
        member.setProvince(editMember.getProvince());
        member.setCity(editMember.getCity());
        return member;
    }

    /**
     * 获取所有购物车内容<对象类型>
     *    【object,object】
     */
    this.getMembersObject = function(){
        var resultMembers = [];
        var members = eval("[" + cookie_get(cookie_member_final) + "]");
        $.each(members,function(i,m1){
            if(m1 != null && m1 != undefined){
                resultMembers.push(member_copy_json_to_Object(m1));
            }
        });
        return resultMembers;
    };
    /**
     * 获取所有购物车内容<Json字符类型类型>
     *     【{json}，{json}】;
     */
    this.getMembersJson = function(){
        var resultMembers = [];
        var members = eval("[" + cookie_get(cookie_member_final) + "]");
        $.each(members,function(i,m1){
            if(m1 != null && m1 != undefined){
                resultMembers.push(member_copy_json_to_Object(m1).toJson_());
            }
        });
        return resultMembers;
    };

    /**
     * 具有覆盖性质的操作<添加购物车>
     *      添加全部购物车
     *      ["{id:'"+this.id+"',num:'"+this.id+"',name:'"+this.name+"'}",{} ]
     * @param members
     */
    this.addMembers = function(members){
        add(cookie_member_final,members);
    };

    /**
     * 添加商品
     *      增加购物商品
     * @param member 一个商品
     * eg:
     *  Object
     */
    this.addMember = function(newMember){
        var members = this.getMembersJson();
        if(members == null || members == undefined || members.length == 0){
            members = [];
        }
        members.push(newMember.toJson_());
        add(cookie_member_final,members);
    };

    /**
     * 更新商品内容
     * @param editMember
     */
    this.editMember = function(editMember){
        var newPerson = [];
        var members = this.getMembersObject();
        if(members == null || members == undefined || members.length == 0){
            members = [];
        }
        $.each(members,function(i,m1){
            if(m1 != null && m1 != undefined){

                /**默认添加*/
                var member = member_copy_json_to_Object(m1);

                /**相同更新*/
                if(editMember.getId() == m1.id){
                    member =member_copy_Object_to_Object(editMember);
                }
                newPerson.push(member.toJson_());
            }
        });
        add(cookie_member_final,newPerson);
    };

    /**
     * 删除购物车商品，指定商品ID 删除
     * @param newMember
     */
    this.delMember = function(newMember){
        var newPerson = [];
        var members = this.getMembersObject();
        if(members == null || members == undefined || members.length == 0){
            members = [];
        }
        $.each(members,function(i,m1){
            if(m1 != null && m1 != undefined){
                if(newMember.getId() != m1.id){
                    newPerson.push(member_copy_json_to_Object(m1).toJson_());
                }

            }
        });
        add(cookie_member_final,newPerson);
    };

    /**
     * 根据ID查询商品
     * @param strId  返回对象
     *  Object
     */
    this.findByIdMember = function(id){
        var findProject = null;
        var members = this.getMembersObject();
        if(members == null || members == undefined || members.length == 0){
            members = [];
        }
        $.each(members,function(i,m1){
            if(m1 != null && m1 != undefined){
                if(id == m1.id){
                    findProject = member_copy_json_to_Object(m1);
                }
            }
        });
        return findProject;
    };
    
}

/**
 * 添加购买商品数量
 * @param {Object} productId
 * @return {TypeName} 
 */
function addMemberToCookie(id,name,phone,postcode,province,city,country,address){
	var memberCookieService = new  MemberCookieService();
	var member = new Member();
	//时间生产策略
	member.setName(name);
	member.setPhone(phone);
	member.setPostcode(postcode);
	member.setProvince(province);
	member.setCity(city);
	member.setCountry(country);
	member.setAddress(address);
	if(id==""){
		id=getDate();
		member.setId(id);
		memberCookieService.addMember(member);
	}else{
		member.setId(id);
		memberCookieService.editMember(member);
	}
	
	//初始化订单收货人
				$("#memberInfo").html(member.name+"&nbsp;&nbsp;&nbsp;"+member.phone+"&nbsp;&nbsp;&nbsp;"+member.country+" "+member.address);
				$("#id2").val(member.id);
				$("#name2").val(member.name);
				$("#phone2").val(member.phone);
				$("#province2").val(member.province);
				$("#city2").val(member.city);
				$("#country2").val(member.country);
				$("#address2").val(member.address);
				$("#defaultFlag2").val(member.defaultFlag);
}

//获得唯一标识符
function getDate(){
	var d = new Date();
	var vYear = d.getFullYear();
	var vMon = d.getMonth() + 1;
	var vDay = d.getDate();
	var h = d.getHours();
	var m = d.getMinutes(); 
	var se = d.getSeconds(); 
	var s=vYear+(vMon<10 ? "0" + vMon : vMon)+(vDay<10 ? "0"+ vDay : vDay)+(h<10 ? "0"+ h : h)+(m<10 ? "0" + m : m)+(se<10 ? "0" +se : se);
	return s;
}

//获得唯一标识符
function getNowDate(){
	var d = new Date();
	var vYear = d.getFullYear();
	var vMon = d.getMonth() + 1;
	var vDay = d.getDate();
	var h = d.getHours();
	var m = d.getMinutes(); 
	var se = d.getSeconds(); 
	var s=vYear+"-"+(vMon<10 ? "0" + vMon : vMon)+"-"+(vDay<10 ? "0"+ vDay : vDay)+" "+(h<10 ? "0"+ h : h)+":"+(m<10 ? "0" + m : m)+":"+(se<10 ? "0" +se : se);
	return s;
}

/**
 * 初始化收货人信息列表
 */
function initMember(){
	var memberCookieService = new  MemberCookieService();
	var members = memberCookieService.getMembersObject();
	if(members != null && members.length > 0){
		$("#memberList").empty();
		var memberInfo="";
		$.each(members,function(i,member){
			//初始化订单收货人
			if(i==members.length-1){//member.postcode=="1"
				$("#memberInfo").html(member.name+"&nbsp;&nbsp;&nbsp;"+member.phone+"&nbsp;&nbsp;&nbsp;"+member.city+"&nbsp;&nbsp;&nbsp;"+member.country+"&nbsp;&nbsp;&nbsp;"+member.address);
				$("#id2").val(member.id);
				$("#name2").val(member.name);
				$("#phone2").val(member.phone);
				$("#province2").val(member.province);
				$("#city2").val(member.city);
				$("#country2").val(member.country);
				$("#address2").val(member.address);
				$("#defaultFlag2").val(member.defaultFlag);
				
				//初始化弹出层
				$("#name").val(member.name);
				$("#phone").val(member.phone);
				$("#country").val(member.country);
				$("#address").val(member.address);
			}
			
			//初始化收货人列表
			/*memberInfo+="<div class=\"row pc_cursor\" data-toggle=\"modal\" onclick=\"chooseAddressInfo("+member.id+")\">";
			memberInfo+="<div class=\"col-md-7 text-left\">";
			memberInfo+=(i+1)+"&nbsp;&nbsp;&nbsp;"+member.name+"&nbsp;&nbsp;&nbsp;"+member.phone+"&nbsp;&nbsp;&nbsp;"+member.country+"&nbsp;&nbsp;&nbsp;"+member.address;
			memberInfo+="</div>";
			memberInfo+="</div>";
			memberInfo+="<hr>";*/
		});
		/*memberInfo+="<div class=\"row pc_cursor\" data-toggle=\"modal\" data-target=\"#memberDiv\" onclick=\"$('#closeMemberList').click();\">";
		memberInfo+="<div class=\"col-md-7 text-left\">";
		memberInfo+="<u>Add</u>"
		memberInfo+="</div>";
		memberInfo+="</div>";
		$("#memberList").html(memberInfo);*/
		
		//addressDiv 打开的层
		//$("#addressDiv").attr("data-target","#memberListDiv");
	}else{
		$("#memberInfo").html("请填写收货人信息!");
		//$("#addressDiv").attr("data-target","#memberDiv");
	}
	
	//初始化总金额总数量
	var cookieService = new  MallCookieService();
	var products = cookieService.getCarsObject();
	var totalNumber=0;
	var amount=0;
	
	if(products != null && products.length > 0){
		$.each(products,function(i,product){
			amount += (numberConvertor(product.price) * numberConvertor(product.getNumber()));
			totalNumber += numberConvertor(product.getNumber());
		});
		
		if(amount<lowFee){
			amount += fee;
			$("#totalAmountDesc").show();
		}else{
			$("#totalAmountDesc").hide();
		}
		$("#totalAmount").val(amount.toFixed(2));
		$("#totalCount").val(totalNumber);
		$("#strongAmount").text("￥"+amount.toFixed(2));
	}else{
		$("#totalAmount").val("0");
		$("#totalCount").val("0");
		$("#strongAmount").text("￥0.00");
	}
}

function chooseAddressInfo(id){
	var memberCookieService = new  MemberCookieService();
	var member = memberCookieService.findByIdMember(id);
	if(null!=member && ""!=member){
		$("#memberInfo").html(member.name+"&nbsp;&nbsp;&nbsp;"+member.phone+"&nbsp;&nbsp;&nbsp;"+member.country+" "+member.address);
		$("#id2").val(member.id);
		$("#name2").val(member.name);
		$("#phone2").val(member.phone);
		$("#province2").val(member.province);
		$("#city2").val(member.city);
		$("#country2").val(member.country);
		$("#address2").val(member.address);
		$("#defaultFlag2").val(member.defaultFlag);
	}
	$("#closeMemberList").click();
}
function deleteCartCookie(){
	var cookieService = new  MallCookieService();
	var products = cookieService.getCarsObject();
	if(products != null && products.length > 0){
		$.each(products,function(i,product){
			cookieService.delProduct(product);
		});
	}
}
